﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Framework.Library.Base.Base;
using Framework.Library.Data.DAL.JObject;
using Framework.Library.Data.DAO;
using Framework.Library.Data.DAL;
using Framework.Library.Core.Utils;
using Framework.Library.Core.Utils.URLBuilder;

namespace Framework.Portal.Layouts.Admin.Components.BGTT.Courses
{
    public partial class CoursesManager : BaseControl
    {
        private readonly string MENUNAME = string.Empty;

        public CoursesManager()
        {
        }

        public CoursesManager(JSection section)
        {
            MENUNAME = section.title;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {               
                lblCommandName.Text = MENUNAME;
            }
        }

        protected void dtgUsers_ItemCommand(object sender, RepeaterCommandEventArgs e)
        {
            int userId = ConvertUtility.ToInt32(e.CommandArgument);
            switch (e.CommandName)
            {
                case "setpedagogue":
                    try
                    {
                        PortalUser info = ManagerFactory.DAOEntity.GetInfo<PortalUser>(new PortalUser() { USERID = userId });
                        if (info != null)
                        {

                        }
                        lblUpdateStatus.Text = Localization.GetText("MESSAGE", "MSG_UPDATE_SUCCESS");
                        LoadUser("");
                    }
                    catch (Exception ex)
                    {
                        lblUpdateStatus.Text = ex.Message;
                    }
                    break;
                default:
                    break;
            }
        }

        protected void btnCreate_Click(object sender, EventArgs e)
        {
            var urlParser = new SimpleURLParameterParser(Request.RawUrl);
            var lstUrl = new Dictionary<string, string>();
            lstUrl.Add("t", "1");
            Response.Redirect(urlParser.CreateQueryString(lstUrl));
        }

        private void LoadUser(string filter)
        {
            List<PortalUser> dtUsers = ManagerFactory.PortalUserManager.GetUsers("%" + filter + "%");
            dtgUsers.DataSource = dtUsers;
            dtgUsers.DataBind();
        }
    }
}